package com.xintoucloud.pbs.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xintoucloud.pbs.entity.PartyBranchContributeState;
import com.xintoucloud.pbs.entity.PartyBranchInformationContribute;
import com.xintoucloud.pbs.service.PartyBranchContributeStateService;

// 支部投稿被审核状态 控制器
@Controller
@RequestMapping("/PartyBranchContributeState")
public class PartyBranchContributeStateController {
    
	@Autowired
	private PartyBranchContributeStateService pbcsService;
	
	@RequestMapping("/addView")
	public String listView(Model m) {
		return "pbcsAdd";
	}
	
	@PostMapping("/add")
	public String add(@Validated PartyBranchContributeState p) {
		boolean result = pbcsService.save(p);
		return "success";
	}


/*	@RequestMapping("/delete")
	public String delete(int id) {
		userService.delete(id);
		return "redirect:list";
	}
	
	@RequestMapping("/tolist")
	public String tolist() {
		return "list";
	}
	
	
	@GetMapping("/get")
	public String get(int id,Model m) {
		m.addAttribute("user", userService.getOne(id));
		return "/update";
	}

	@GetMapping("/signup")
	public String tosignup() {
		return "signup";
	}
	
	@PostMapping("/signup")
	//@RequestMapping("/signup")
	//现在使用注解,要用@Validated指定的是User类中的属性参数, 用BindingResult获取错误
	public String signup(@Validated User user,BindingResult result,Model m) {
		if(result.hasErrors()) {  //如果有错误
			List<ObjectError> errors = result.getAllErrors();
			Map<String,String> errorMessages = new HashMap<>();
			for(ObjectError oe: errors) {   
				if(oe instanceof FieldError) {  //如果错误属于字段名错误,将字段名和错误提示信息存到map集合中
					FieldError fe = (FieldError)oe;
					String fieldName = fe.getObjectName();
					String fieldMessage = fe.getDefaultMessage();
					errorMessages.put(fieldName, fieldMessage);
				}
			}    //将map集合放于model中, 发送到jsp页面用El,jstl就可以显示出来
			m.addAttribute("errorMessages", errorMessages);  
			return "signup";
		}
		boolean result2 = userService.save(user);
		if(result2) {
			System.out.println("已注册新用户"+"username="+user.getUname());
		}
		return "redirect:signin";
		
	}
	
	
	@GetMapping("signin")
	public String tosignin() {
		return "signin";
	}

	@PostMapping("signin")
	public String signin(String uname, String upass, HttpSession session) {
		User loginUser = userService.login(uname, upass);
		if(loginUser != null) {
			session.setAttribute("loginUser", loginUser);
			return "redirect:list";
		}
		return "signin";
	}
	
	//@RequestMapping(value="/get",method=RequestMethod.POST) //只处理post请求
	//@PostMapping("/update")
	@RequestMapping("/update")
	public String update(User user,Model m) {
		userService.update(user);
		return "redirect:list";
	}*/
}
